<default-header class="top-header"></default-header>
<div class="wrap no-sidebar">
  <div class="sidebar-left collapse navbar-collapse navbar-collapse-2">
    <navbar-utility-mobile></navbar-utility-mobile>
  </div>
  <div class="middle">
    <!-- Middle section -->
    <div class="middle-section surface-shaded" ng-show="buildConfig">
      <div id="scrollable-content" class="middle-container has-scroll">
        <div class="middle-content">
          <div class="container surface-shaded">
            <breadcrumbs breadcrumbs="breadcrumbs"></breadcrumbs>
            <alerts alerts="alerts"></alerts>
            <div ng-if="!loaded">{{'Loading' | translate}}...</div>
            <h1>
              Edit Build Config {{buildConfig.metadata.name}} - <small>{{strategyType}} Build Strategy</small>
            </h1>
            <fieldset ng-disabled="disableInputs">
              <form class="edit-form" name="form" novalidate>
                <div class="resource-details">
                  <div class="row">
                    <div class="col-lg-6">
                      <div class="section">
                        <h3>Source Configuration</h3>
                        <dl class="dl-horizontal left">
                          <div ng-if="sources.git">
                            <div class="form-group">
                              <label for="sourceUrl">Source Repository URL</label>
                              <div>
                                <!-- Unfortunately, we can't set type="url" because some valid values don't pass browser validation. -->
                                <input class="form-control"
                                  id="sourceUrl"
                                  name="sourceUrl"
                                  ng-model="updatedBuildConfig.spec.source.git.uri"
                                  type="text"
                                  autocorrect="off"
                                  autocapitalize="off"
                                  spellcheck="false"
                                  required>
                              </div>
                              <div>
                                <span class="text-warning" ng-if="form.sourceUrl.$dirty && !sourceURLPattern.test(updatedBuildConfig.spec.source.git.uri)">Git repository should be a URL.</span>
                              </div>
                            </div>

                            <div class="form-group editor">
                              <label for="sourceRef">Source Repository Ref</label>
                              <div>
                                <input class="form-control"
                                  id="sourceRef"
                                  name="sourceRef"
                                  type="text"
                                  ng-model="updatedBuildConfig.spec.source.git.ref"
                                  placeholder="master"
                                  autocorrect="off"
                                  autocapitalize="off"
                                  spellcheck="false">
                              </div>
                            </div>

                            <div class="form-group">
                              <label for="sourceContextDir">Source Context Dir</label>
                              <div>
                                <input class="form-control"
                                  id="sourceContextDir"
                                  name="sourceContextDir"
                                  type="text"
                                  ng-model="updatedBuildConfig.spec.source.contextDir"
                                  placeholder="/"
                                  autocorrect="off"
                                  autocapitalize="off"
                                  spellcheck="false">
                              </div>
                            </div>
                          </div>

                          <div ng-if="sources.dockerfile">
                            <div class="form-group">
                            <label for="buildFrom">Dockerfile</label>
                              <div ui-ace="{
                                mode: 'dockerfile',
                                theme: 'eclipse',
                                onLoad: aceLoaded,
                                rendererOptions: {
                                  fadeFoldWidgets: true,
                                  showPrintMargin: false
                                }
                              }" ng-model="updatedBuildConfig.spec.source.dockerfile" class="ace_editor-bordered dockerfile-editor dockerfile-mode"></div>
                            </div>

                            <div class="form-group" ng-if="updatedBuildConfig.spec.strategy.dockerStrategy.dockerfilePath">
                              <label for="dockerfilePath">Dockerfile Path</label>
                              <div>
                                <input class="form-control"
                                  id="dockerfilePath"
                                  name="dockerfilePath"
                                  type="text"
                                  ng-model="updatedBuildConfig.spec.strategy.dockerStrategy.dockerfilePath"
                                  autocorrect="off"
                                  autocapitalize="off"
                                  spellcheck="false">
                              </div>
                            </div>
                          </div>

                          <div class="form-group" ng-if="strategyType === 'Docker'">
                            <div class="checkbox">
                              <label>
                                <input type="checkbox" ng-model="options.noCache"/>
                                Execute docker build without reusing cached instructions.
                                <span class="help action-inline">
                                  <a href>
                                    <i class="pficon pficon-help" data-toggle="tooltip" aria-hidden="true" data-placement="right" data-original-title="Will run the docker build with '--no-cache=true' flag">
                                    </i>
                                  </a>
                                </span>
                              </label>
                            </div>
                          </div>

                          <div ng-if="sources.binary && updatedBuildConfig.spec.source">
                            <div class="form-group">
                              <label for="binaryAsBuild">
                                Binary Input As File
                                <span class="help action-inline">
                                  <a href>
                                    <i class="pficon pficon-help" data-toggle="tooltip" data-placement="right" aria-hidden="true" data-original-title="Indicates that the provided binary input should be considered a single file within the build input. For example, specifying 'webapp.war' would place the provided binary as '/webapp.war' for the builder. If left empty, the Docker and Source build strategies assume this file is a zip, tar, or tar.gz file and extract it as the source. The custom strategy receives this binary as standard input. This filename may not contain slashes or be '..' or '.'."></i>
                                  </a>
                                </span>
                              </label>
                              <div>
                                <input class="form-control"
                                  id="binaryAsBuild"
                                  name="binaryAsBuild"
                                  type="text"
                                  ng-model="options.binaryAsFile"
                                  autocorrect="off"
                                  autocapitalize="off"
                                  spellcheck="false">
                              </div>
                            </div>
                          </div>

                          <div class="form-groups" ng-show="sources.images">

                            <div class="single-image-source" ng-if="sourceImages.length === 1">
                              <div class="form-group">
                                <label for="imageSourceFrom">Image Source From</label>
                                <select
                                  class="form-control simpleselector"
                                  ng-model="imageSourceOptions.pickedType"
                                  ng-options="type.id as type.title for type in imageSourceTypes"
                                  ng-change="assambleInputType('imageSource', imageSourceOptions.pickedType)">
                                </select>
                              </div>

                              <div class="row form-group" ng-if="imageSourceOptions.pickedType==='ImageStreamTag'" >
                                <div class="col-sm-4">
                                 <div class="form-group">
                                    <label>Namespace</label>
                                    <span ng-if="!isNamespaceAvailable(imageSourceOptions.pickedNamespace)" data-toggle="tooltip" data-placement="right" title="Selected Namespace is not available." class="pficon pficon-error-circle-o" style="cursor: help;"></span>
                                    <select
                                      name="imageSourceNamespace"
                                      class="form-control"
                                      ng-model="imageSourceOptions.pickedNamespace"
                                      ng-options="name for name in imageSourceBuildFrom.projects track by name"
                                      ng-change="updateImageSourceImageStreams(imageSourceOptions.pickedNamespace, true)"
                                      required>
                                    </select>
                                  </div>
                                </div>

                                <div class="col-sm-4">
                                  <div class="form-group">
                                    <label>Image Stream</label>
                                    <span  ng-if="inspectNamespace(imageSourceBuildFrom.imageStreams, imageSourceOptions.pickedImageStream) === 'empty'" data-toggle="tooltip" data-placement="right" title="Selected Namespace doesn't contain any Image Streams to build from." class="pficon pficon-error-circle-o" style="cursor: help;"></span>
                                    <span  ng-if="inspectNamespace(imageSourceBuildFrom.imageStreams, imageSourceOptions.pickedImageStream) === 'noMatch'" data-toggle="tooltip" data-placement="right" title="Selected Namespace doesn't contain Image Stream choosen Tag" class="pficon pficon-error-circle-o" style="cursor: help;"></span>
                                    <select
                                      name="imageSourceImageStream"
                                      class="form-control"
                                      ng-model="imageSourceOptions.pickedImageStream"
                                      ng-options="name as name for name in imageSourceBuildFrom.imageStreams track by name"
                                      ng-change="clearSelectedTag(imageSourceOptions, imageSourceBuildFrom.tags)"
                                      required>
                                    </select>
                                  </div>
                                </div>

                                <div class="col-sm-4">
                                  <div class="form-group">
                                    <label>Tag</label>
                                    <span ng-if="inspectTags(imageSourceBuildFrom.tags, imageSourceOptions.pickedImageStream, imageSourceOptions.pickedTag) === 'empty'" data-toggle="tooltip" data-placement="right" title="Selected Image Stream doesn't contain any tagged image to build from." class="pficon pficon-error-circle-o" style="cursor: help;"></span>
                                    <span ng-if="inspectTags(imageSourceBuildFrom.tags, imageSourceOptions.pickedImageStream, imageSourceOptions.pickedTag) === 'noMatch'" data-toggle="tooltip" data-placement="right" title="Selected Image Stream doesn't contain choosen Tag." class="pficon pficon-error-circle-o" style="cursor: help;"></span>
                                    <select
                                      name="imageSourceTag"
                                      class="form-control"
                                      ng-model="imageSourceOptions.pickedTag"
                                      ng-options="name as name for name in imageSourceBuildFrom.tags[imageSourceOptions.pickedImageStream] track by name"
                                      ng-disabled="imageSourceOptions.pickedImageStream === ''"
                                      required>
                                    </select>
                                  </div>
                                </div>
                              </div>

                              <div ng-if="imageSourceOptions.pickedType==='ImageStreamImage'" class="form-group">
                                <label for="imageSourceImage">Image Stream Image</label>
                                <div>
                                  <input class="form-control"
                                    type="text"
                                    ng-model="imageSourceOptions.pickedImageStreamImage"
                                    placeholder="example: ruby-20-centos7@603bfa418"
                                    autocorrect="off"
                                    autocapitalize="off"
                                    spellcheck="false"
                                    required>
                                </div>
                              </div>


                              <div ng-if="imageSourceOptions.pickedType==='DockerImage'" class="form-group">
                                <label for="imageSourceLink">Docker Image Link</label>
                                <div>
                                  <input class="form-control"
                                    id="imageSourceLink"
                                    name="imageSourceLink"
                                    type="text"
                                    ng-model="imageSourceOptions.pickedDockerImage"
                                    placeholder="example: openshift/ruby-20-centos7:latest"
                                    autocorrect="off"
                                    autocapitalize="off"
                                    spellcheck="false"
                                    required>
                                </div>
                              </div>

                              <div class="form-group">
                                <label for="buildFrom">Source and Destination Paths<span class="help action-inline">
                                  <a href>
                                  <i class="pficon pficon-help" data-toggle="tooltip" data-placement="right" aria-hidden="true" data-original-title="Paths is a list of source and destination paths to copy from the image. At least one pair has to be specified."></i>
                                  </a>
                                </span></label>
                                <osc-key-values
                                  entries="imageSourcePaths"
                                  readonly-keys=""
                                  delimiter="="
                                  delete-policy="always"
                                  key-validator="path"
                                  key-title="Source Path"
                                  value-title="Destination Dir"
                                  prevent-empty="true"
                                  key-validation-tooltip="A valid Source Path is an absoluth path beginning with '/'"></osc-key-values>
                              </div>
                            </div>


                            <div class="multiple-image-source" ng-if="sourceImages.length !== 1">
                              <label for="imageSourceFrom">Image Source From</label>
                              <div ng-repeat="fromObject in imageSourceFromObjects" class="imageSourceItem">
                                {{selectTypes[fromObject.kind]}}: {{fromObject | imageObjectRef : buildConfig.metadata.namespace}}
                              </div>
                            </div>
                          </div>
                        </dl>
                      </div>

                      <div class="section">
                        <h3>Image Configuration</h3>
                        <dl class="dl-horizontal left">

                          <div>
                            <div class="form-group">
                              <label for="buildFrom">Build From</label>
                              <select
                                class="form-control simpleselector"
                                ng-model="builderOptions.pickedType"
                                ng-options="type.id as type.title for type in buildFromTypes"
                                ng-change="assambleInputType('builder', builderOptions.pickedType)">
                              </select>
                            </div>

                            <div class="row form-group" ng-if="builderOptions.pickedType==='ImageStreamTag'">
                              <div class="col-sm-4">
                                <div class="form-group">
                                  <label>Namespace</label>
                                  <span  ng-if="!isNamespaceAvailable(builderOptions.pickedNamespace)" data-toggle="tooltip" data-placement="right" title="Selected Namespace is not available." class="pficon pficon-error-circle-o" style="cursor: help;"></span>
                                  <select
                                    class="form-control"
                                    ng-model="builderOptions.pickedNamespace"
                                    ng-options="name for name in buildFrom.projects track by name"
                                    ng-change="updateBuilderImageStreams(builderOptions.pickedNamespace, true)"
                                    required>
                                  </select>
                                </div>
                              </div>
                              <div class="col-sm-4">
                                <div class="form-group">
                                  <label>Image Stream</label>
                                  <span  ng-if="inspectNamespace(buildFrom.imageStreams, builderOptions.pickedImageStream) === 'empty'" data-toggle="tooltip" data-placement="right" title="Selected Namespace doesn't contain any Image Streams to build from." class="pficon pficon-error-circle-o" style="cursor: help;"></span>
                                  <span  ng-if="inspectNamespace(buildFrom.imageStreams, builderOptions.pickedImageStream) === 'noMatch'" data-toggle="tooltip" data-placement="right" title="Selected Namespace doesn't contain Image Stream choosen Tag" class="pficon pficon-error-circle-o" style="cursor: help;"></span>
                                  <select
                                    class="form-control"
                                    ng-model="builderOptions.pickedImageStream"
                                    ng-options="name as name for name in buildFrom.imageStreams track by name"
                                    ng-change="clearSelectedTag(builderOptions, buildFrom.tags)"
                                    required>
                                  </select>
                                </div>
                              </div>

                              <div class="col-sm-4">
                                <div class="form-group">
                                  <label>Tag</label>
                                  <span ng-if="inspectTags(buildFrom.tags, builderOptions.pickedImageStream, builderOptions.pickedTag) === 'empty'" data-toggle="tooltip" data-placement="right" title="Selected Image Stream doesn't contain any tagged image to build from." class="pficon pficon-error-circle-o" style="cursor: help;"></span>
                                  <span ng-if="inspectTags(buildFrom.tags, builderOptions.pickedImageStream, builderOptions.pickedTag) === 'noMatch'" data-toggle="tooltip" data-placement="right" title="Selected Image Stream doesn't contain choosen Tag." class="pficon pficon-error-circle-o" style="cursor: help;"></span>
                                  <select
                                    class="form-control"
                                    ng-model="builderOptions.pickedTag"
                                    ng-options="name as name for name in buildFrom.tags[builderOptions.pickedImageStream] track by name"
                                    ng-disabled="builderOptions.pickedImageStream === ''"
                                    required>
                                  </select>
                                </div>
                              </div>
                            </div>

                            <div ng-if="builderOptions.pickedType==='DockerImage'" class="form-group">
                              <label for="FromTypeLink">Docker Image Link</label>
                              <div>
                                <input class="form-control"
                                  type="text"
                                  ng-model="builderOptions.pickedDockerImage"
                                  placeholder="example: openshift/ruby-20-centos7:latest"
                                  autocorrect="off"
                                  autocapitalize="off"
                                  spellcheck="false"
                                  required>
                              </div>
                            </div>

                            <div ng-if="builderOptions.pickedType==='ImageStreamImage'" class="form-group">
                              <label for="FromTypeImage">Image Stream Image</label>
                              <div>
                                <input class="form-control"
                                  type="text"
                                  ng-model="builderOptions.pickedImageStreamImage"
                                  placeholder="example: ruby-20-centos7@603bfa418"
                                  autocorrect="off"
                                  autocapitalize="off"
                                  spellcheck="false"
                                  required>
                              </div>
                            </div>

                          </div>

                          <div class="form-group">
                            <div class="checkbox">
                              <label>
                                <input type="checkbox" ng-model="options.forcePull"/>
                                Always pull the builder image from the docker registry, even if it is present locally
                              </label>
                            </div>
                          </div>

                          <div>
                            <div class="form-group">
                              <label for="buildFrom">Push To</label>
                              <select
                                class="form-control simpleselector"
                                ng-model="outputOptions.pickedType"
                                ng-options="type.id as type.title for type in pushToTypes"
                                ng-change="assambleInputType('output', outputOptions.pickedType)">
                              </select>
                            </div>

                            <div class="row form-group" ng-if="outputOptions.pickedType==='ImageStreamTag'">
                              <div class="col-sm-4">
                               <div class="form-group">
                                  <label>Namespace</label>
                                  <span  ng-if="!isNamespaceAvailable(outputOptions.pickedNamespace)" data-toggle="tooltip" data-placement="right" title="Selected Namespace is not available." class="pficon pficon-error-circle-o" style="cursor: help;"></span>
                                  <select
                                    class="form-control"
                                    id="outputNamespace"
                                    name="outputNamespace"
                                    ng-model="outputOptions.pickedNamespace"
                                    ng-options="name for name in pushTo.projects track by name"
                                    ng-change="updateOutputImageStreams(outputOptions.pickedNamespace, true)"
                                    required>
                                  </select>
                                </div>
                              </div>
                              <div class="col-sm-4">
                                <div class="form-group">
                                  <label>Image Stream</label>
                                  <span  ng-if="inspectNamespace(pushTo.imageStreams, outputOptions.pickedImageStream) === 'empty'" data-toggle="tooltip" data-placement="right" title="Selected Namespace doesn't contain any Image Streams to build from." class="pficon pficon-error-circle-o" style="cursor: help;"></span>
                                  <span  ng-if="inspectNamespace(pushTo.imageStreams, outputOptions.pickedImageStream) === 'noMatch'" data-toggle="tooltip" data-placement="right" title="Selected Namespace doesn't contain Image Stream choosen Tag" class="pficon pficon-error-circle-o" style="cursor: help;"></span>
                                  <select
                                    class="form-control"
                                    id="outputImageStream"
                                    name="outputImageStream"
                                    ng-model="outputOptions.pickedImageStream"
                                    ng-options="name as name for name in pushTo.imageStreams track by name"
                                    ng-change="clearSelectedTag(outputOptions, pushTo.tags, true)"
                                    required>
                                  </select>
                                </div>
                              </div>

                              <div class="col-sm-4">
                                <div class="form-group">
                                  <label>Tag</label>
                                  <span  ng-if="showOutputTagWarning(form)" data-toggle="tooltip" data-placement="right" title="Tag is already created and will be overridden on build." class="pficon pficon-warning-triangle-o" style="cursor: help;"></span>
                                  <div>
                                  <input class="form-control"
                                    id="outputTag"
                                    name="outputTag"
                                    type="text"
                                    ng-model="outputOptions.pickedTag"
                                    ng-disabled="outputOptions.pickedImageStream === ''"
                                    autocorrect="off"
                                    autocapitalize="off"
                                    spellcheck="false"
                                    required>
                                  </div>
                                </div>
                              </div>
                            </div>

                            <div ng-if="outputOptions.pickedType==='DockerImage'" class="form-group">
                              <label for="pushToLink">Docker Image Link</label>
                              <div>
                                <input class="form-control"
                                  id="pushToLink"
                                  name="pushToLink"
                                  type="text"
                                  ng-model="outputOptions.pickedDockerImage"
                                  autocorrect="off"
                                  autocapitalize="off"
                                  spellcheck="false"
                                  required>
                              </div>
                            </div>
                          </div>
                        </dl>
                      </div>
                    </div>


                    <div class="col-lg-6">
                      <div class="section">
                        <h3>Environment Variables<span class="help action-inline">
                          <a href>
                          <i class="pficon pficon-help" data-toggle="tooltip" data-placement="left" aria-hidden="true" data-original-title="Environment variables are used to configure and pass information to running containers.  These environment variables will be available during your build and at runtime."></i>
                          </a>
                        </span></h3>
                        <div>
                          <osc-key-values
                            entries="envVars"
                            delimiter="="
                            key-validator="env"
                            delete-policy="always"
                            key-title="Name"
                            key-validation-tooltip="A valid environment variable name is an alphanumeric (a-z and 0-9) string beginning with a letter that may contain underscores."></osc-key-values>
                        </div>
                      </div>
                      <div class="section">
                        <h3>Triggers</h3>
                        <dl class="dl-horizontal left">
                          <div>
                            <div class="checkbox" ng-if="sources.git" >
                              <label>
                                <input type="checkbox" ng-model="pickedTriggers['webhook']"/>
                                Enable the webhook build trigger
                                <span class="help action-inline">
                                  <a href>
                                    <i class="pficon pficon-help" data-toggle="tooltip" data-placement="left" aria-hidden="true" data-original-title="The source repository must be configured to use the webhook to trigger a build when source is committed.">
                                    </i>
                                  </a>
                                </span>
                              </label>
                            </div>
                            <div class="checkbox">
                              <label>
                                <input type="checkbox" ng-model="pickedTriggers['imageChange']" ng-disabled="builderOptions.pickedType === 'None'"/>
                                Automatically build a new image when the builder image changes
                                <span class="help action-inline">
                                  <a href>
                                    <i class="pficon pficon-help" data-placement="left" aria-hidden="true"
                                    data-toggle="tooltip" data-original-title="Automatically building a new image when the builder image changes allows your code to always run on the latest updates.">
                                  </i>
                                  </a>
                                </span>
                              </label>
                            </div>
                            <div class="checkbox">
                              <label>
                                <input type="checkbox" ng-model="pickedTriggers['configChange']"/>
                                Automatically build a new image when the build configuration changes
                              </label>
                            </div>
                          </div>
                        </dl>
                      </div>
                    </div>
                  </div>
                    <div class="buttons gutter-top-bottom">
                      <button class="btn btn-primary btn-lg"
                          ng-click="save()"
                          ng-disabled="form.$invalid || form.$pristine || disableInputs">
                          Save
                      </button>
                      <a class="btn btn-default btn-lg"
                        href="{{buildConfig.metadata.name | navigateResourceURL : 'BuildConfig' : projectName}}">
                        Cancel
                      </a>
                    </div>
                  </div>
              </form>
            </fieldset>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
